﻿/*
 * Test classes for SSAS Partition Manager 
 * https://ssaspartitionmanager.codeplex.com/
 * 
 * Written by Dr. John Tunnicliffe of Decision Analytics, May 2015
 * eMail: john@decision-analytics.co.uk 
 * http://www.decision-analytics.co.uk/
 * https://www.linkedin.com/in/drjohntunnicliffe
 * 
 * Tests written with FluentAssertions, XUnit and Moq which can be installed from Nuget.  
 * 
 * FluentAssertions
 * http://www.fluentassertions.com/ 
 * 
 * XUnit
 * http://xunit.github.io/
 * 
 * Moq
 * https://github.com/Moq/moq4
 */

namespace AmoExtensions.UnitTests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Dynamic;
    using AmoExtensions;
    using FluentAssertions;
    using Xunit;
    using Moq;

    public class UnitTestPartitionManager
    {
        private const string MustCallGetListOfPartitions = "You must call populate ListOfPartitions yourselve or call GetListOfPartitions*";

        #region Constructor Tests
        [Fact]
        public void Constructor_NullServerThrowsException()
        {
            Action action = () => new PartitionManager(null, null);
            action
                .ShouldThrow<ArgumentNullException>();
        }

        [Fact]
        public void Constructor_DisconnectedServerThrowsException()
        {
            // setup
            IAmoServer server = MockObjects.GetMockedDisconnectedServer();

            // test
            Action action = () => new PartitionManager(server, null);
            action
                .ShouldThrow<ApplicationException>()
                .WithMessage("SSAS Server not connected");
        }

        [Fact]
        public void Constructor_NullListOfPartitionsThrowsException()
        {
            // setup
            IAmoServer server = MockObjects.GetMockedConnectedServer();

            // test
            Action action = () => new PartitionManager(server, null);
            action
                .ShouldThrow<ArgumentNullException>();
        }
        #endregion

        #region ListOfPartitions Tests
        [Fact]
        public void ListOfPartitions_ReturnsOnePartition()
        {
            // setup
            PartitionManager pm = (PartitionManager)MockObjects.GetMockedPartitionManager();

            // test
            int count = pm.ListOfPartitions.Count();
            count.Should().Be(1);
        }
        #endregion

        #region IsPartitionListValid
        [Fact]
        public void IsPartitionListValid_ShouldNotThrow()
        {
            // setup
            IPartitionManager pm = MockObjects.GetMockedPartitionManager();

            // test
            Action action = () => pm.IsPartitionListValid();
            action.ShouldNotThrow();
        }
        #endregion

        #region CreatePartitions Tests
        [Fact]
        public void CreatePartitions_ShouldNotThrow()
        {
            // setup
            IPartitionManager pm = MockObjects.GetMockedPartitionManager();

            // test
            Action action = () => pm.CreatePartitions();
            action.ShouldNotThrow();
        }
        #endregion

        #region DeletePartitions Tests        
        [Fact]
        public void DeletePartitions_ShouldNotThrow()
        {
            // setup
            IPartitionManager pm = MockObjects.GetMockedPartitionManager();
            
            // test
            Action action = () => pm.DeletePartitions();
            action.ShouldNotThrow();
        }
        #endregion

        #region UpdateCubeMetaData
        [Fact]
        public void UpdateCubeMetaData_ShouldNotThrow()
        {
            // setup
            IPartitionManager pm = MockObjects.GetMockedPartitionManager();

            // test
            Action action = () => pm.UpdateCubeMetaData();
            action.ShouldNotThrow();
        }
        #endregion
    }
}
